const getLuckAndForecastGroupNames = (resultArray, currentHistoryItem, numberGroupMap, flatGroupMap) => {
  // 最终合并结果
  // const allGroups = [...filteredSortedA, ...filteredSortedB, ...filteredSortedC]
  const allGroups = [...resultArray]

  // 用 Set 来避免重复的号码
  const luckySet = new Set()

  allGroups.forEach((group, i) => {
    // if (!group?.groupName) {
    //   console.log('不存在的 index', i)
    //   console.log('不存在的', allGroups)
    //   console.log('不存在的', group)
    // }

    const { groupName } = group
    const index = numberGroupMap[currentHistoryItem.number][groupName]
    const sub_array = flatGroupMap[groupName][index]

    if (luckySet.size < 32) {
      // 一个号码一个号码去添加
      sub_array.forEach((number) => {
        if (luckySet.size < 32) {
          i
          luckySet.add(number)
        }
      })
    }
  })

  if (luckySet.size < 32) {
    console.log('luckySet.size', luckySet.size)
  }

  const uniqueLuckyArray = [...luckySet]

  // 生成 1-49 的数组
  const all_numbers = Array.from({ length: 49 }, (_, i) => i + 1).map((num) => (num < 10 ? `0${num}` : `${num}`))

  // 幸运号码
  const lucky_array = uniqueLuckyArray.map((item) => item.toString().padStart(2, '0'))

  // 杀号
  const kill_array = all_numbers.filter(
    (item) => !lucky_array.map((item) => item.toString().padStart(2, '0')).includes(item.toString().padStart(2, '0'))
  )

  return {
    lucky_array,
    kill_array
  }
}

module.exports = getLuckAndForecastGroupNames
